package com.example.classconnect.fragments;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RadioButton;

import com.example.classconnect.LoginActivity;
import com.example.classconnect.R;
import com.example.classconnect.UpdateTable;
import com.example.classconnect.User;

public class UpdateUserInfoFragment extends Fragment {
	public UpdateUserInfoFragment(){};
	private User currentUser;
	private EditText mDescriptionView;
	private EditText mClubsView;
	private EditText mHobbiesView;
	private EditText mHighSchoolView;
	private RadioButton mLiving1View;
	private RadioButton mLiving2View;
	private RadioButton mLiving3View;
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_user_info, container, false);

		currentUser = getArguments().getParcelable("CURRENTUSER");
        mDescriptionView = (EditText) rootView.findViewById(R.id.Desc);
		mClubsView = (EditText) rootView.findViewById(R.id.Club);
		mHobbiesView = (EditText) rootView.findViewById(R.id.Hob);
		mHighSchoolView = (EditText) rootView.findViewById(R.id.HS);
		mLiving1View = (RadioButton) rootView.findViewById(R.id.Dorm);
		mLiving2View = (RadioButton) rootView.findViewById(R.id.Commute);
		mLiving3View = (RadioButton) rootView.findViewById(R.id.offCampus);
		rootView.findViewById(R.id.updateProfile).setOnClickListener(
				
				new View.OnClickListener() {
					@Override
					public void onClick(View view) {
						updateUser();
					}
				});
        return rootView;
    }
	public void updateUser(){
		currentUser.setDescription(mDescriptionView.getText().toString());
		currentUser.setHobbies(mHobbiesView.getText().toString());
		currentUser.setClubs(mClubsView.getText().toString());
		currentUser.setHS(mHighSchoolView.getText().toString());
		if(mLiving1View.isChecked()){
			currentUser.setLiving("Dorm");
		} else
		if(mLiving2View.isChecked()){
			currentUser.setLiving("Commute");
		} else
		if(mLiving3View.isChecked()){
			currentUser.setLiving("Live Off Campus");
		}
		Intent myIntent = new Intent(getActivity(), UpdateTable.class);
		myIntent.putExtra("UPDATEUSER", currentUser);
		getActivity().startActivity(myIntent);
		getActivity().finish();
	}
}